package cn.ejiajunxy.manager.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;

import cn.ejiajunxy.manager.R;
import cn.ejiajunxy.manager.model.OrderModel;

/**
 * Created by zhangguobao on 2018/3/14.
 */

public class ContentAdapter extends RecyclerView.Adapter {
    private List<OrderModel.OrderListBean.ShoppingCartListBean> mShoppingCartListBeans;

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.row_contnet, parent, false));
    }

    public void setData(List<OrderModel.OrderListBean.ShoppingCartListBean> shoppingCartListBeanList) {
        mShoppingCartListBeans = shoppingCartListBeanList;
        notifyDataSetChanged();
    }


    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        OrderModel.OrderListBean.ShoppingCartListBean shoppingCartListBean = mShoppingCartListBeans.get(position);
        ViewHolder viewHolder = (ViewHolder) holder;
        viewHolder.tvPrice.setText(shoppingCartListBean.Amount + "");
        viewHolder.tvNum.setText(shoppingCartListBean.Quantity + "");
        viewHolder.tvName.setText(shoppingCartListBean.Product.productName);
    }


    @Override
    public int getItemCount() {
        if (mShoppingCartListBeans == null) {
            return 0;
        }
        return mShoppingCartListBeans.size();
    }

    private class ViewHolder extends RecyclerView.ViewHolder {
        TextView tvName;
        TextView tvNum;
        TextView tvPrice;


        public ViewHolder(View view) {
            super(view);
            tvName = view.findViewById(R.id.tvTitle);
            tvNum = view.findViewById(R.id.tvNum);
            tvPrice = view.findViewById(R.id.tvPrice);
        }
    }
}
